/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.falco.SE4X;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 *
 * @author Falco
 */
public class EconomyActivity extends Activity {

    private EditText editTextCarryOver;
    private EditText editTextColony;
    private EditText editTextMineral;
    private EditText editTextPipe;
    private EditText editTextMaintenance;
    private EditText editTextBid;
    private EditText editTextTech;
    private EditText editTextShip;
    private EditText editTextUpgrade;
    private EditText editTextMaintIncrease;
    private EditText editTextMaintDecrease;
    private EconomyModel model;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.economy);

        editTextCarryOver = (EditText) findViewById(R.id.edittextCarry);
        editTextColony = (EditText) findViewById(R.id.edittextColony);
        editTextMineral = (EditText) findViewById(R.id.edittextMineral);
        editTextPipe = (EditText) findViewById(R.id.edittextPipe);
        editTextMaintenance = (EditText) findViewById(R.id.edittextMaintenance);
        editTextBid = (EditText) findViewById(R.id.edittextBid);
        editTextTech = (EditText) findViewById(R.id.edittextTech);
        editTextShip = (EditText) findViewById(R.id.edittextShip);
        editTextUpgrade = (EditText) findViewById(R.id.edittextUpgrade);
        editTextMaintIncrease = (EditText) findViewById(R.id.edittextMaintIncrease);
        editTextMaintDecrease = (EditText) findViewById(R.id.edittextMaintDecrease);

        model = new EconomyModel();

    }

    public void process(View view) {
        int duration = Toast.LENGTH_SHORT;

        saveRound();
        clearTable();        
        model.nextRound();
        fillTable();
        
        Toast toast = Toast.makeText(getApplicationContext(), editTextCarryOver.getText(), duration);
        toast.show();



    }

    private void saveRound() {
        model.addCarryOver(Integer.parseInt(editTextCarryOver.getText().toString()));
        model.addColonies(Integer.parseInt(editTextColony.getText().toString()));
        model.addMinerals(Integer.parseInt(editTextMineral.getText().toString()));
        model.addPipe(Integer.parseInt(editTextPipe.getText().toString()));
        model.addMaintenance(Integer.parseInt(editTextMaintenance.getText().toString()));
        model.addBid(Integer.parseInt(editTextBid.getText().toString()));
        model.addTechnology(Integer.parseInt(editTextTech.getText().toString()));
        model.addShip(Integer.parseInt(editTextShip.getText().toString()));
        model.addUpgrades(Integer.parseInt(editTextUpgrade.getText().toString()));
        model.addIncrease(Integer.parseInt(editTextMaintIncrease.getText().toString()));
        model.addDecrease(Integer.parseInt(editTextMaintDecrease.getText().toString()));
    }

    private void clearTable() {

        editTextCarryOver.setText("");
        editTextColony.setText("");
        editTextMineral.setText("");
        editTextPipe.setText("");
        editTextMaintenance.setText("");
        editTextBid.setText("");
        editTextTech.setText("");
        editTextShip.setText("");
        editTextUpgrade.setText("");
        editTextMaintIncrease.setText("");
        editTextMaintDecrease.setText("");
    }

    private void fillTable() {        
        editTextCarryOver.setText(String.valueOf(model.getLastRoundResult()), TextView.BufferType.EDITABLE);
    }
}
